package com.controller.Fxy;

import com.bean.Fxy.Dygl;
import com.bean.Fxy.Lygl;
import com.bean.Fxy.Tjxx;
import com.dao.Fxy.GetData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;

@Controller
@RequestMapping("/Fxypage/")
public class TestController1 {
    @Autowired
    private GetData gd;

    @Resource
    private HttpSession session;

    /**
     * 已完成
     * 加载字段
     *
     * @return
     */
    @RequestMapping(value = "getall", method = RequestMethod.GET)
    @ResponseBody
    public Object getall() {
        // System.out.println(11);
        return gd.getall();
    }

    /**
     * 已完成
     * 点击查询
     *
     * @param inp
     * @return
     */
    @RequestMapping(value = "lgetListxqgl", method = RequestMethod.GET)
    @ResponseBody
    public Object lgetListxqgl(String inp) {

        // System.out.println(11);
        return gd.lgetListxqgl(inp);
    }

    /**
     * 已完成
     * 点击删除
     *
     * @param vid
     * @return
     */
    @RequestMapping(value = "getsc", method = RequestMethod.GET)
    @ResponseBody
    public Object getsc(String vid) {
        return gd.getsc(vid);
    }

    /**
     * 模态框添加小区信息
     */
    @RequestMapping("getTjxx")
    @ResponseBody
    public Object getTjxx( MultipartFile tp,String xqmc, String szdq, String xxdz,
                          String kfdh, String fzr, String lxrdh, String zdmj, String jzmj, String ggcsmj,
                          String lhmj, String sjcwmj, String ckmj, Integer cws, String bz) {

        String uploadFileName = tp.getOriginalFilename();
        String[]  os=uploadFileName.split("\\.");
        String newfilename = System.currentTimeMillis()+"."+os[1];
        String url1 = session.getServletContext().getRealPath("/");
        String url2=url1+"\\img\\"+newfilename;
        File newFile1 = new File(url2);

        try {
            tp.transferTo(newFile1);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        try {
            xqmc  = new String(xqmc.getBytes("ISO-8859-1"),"UTF-8");
            szdq  = new String(szdq.getBytes("ISO-8859-1"),"UTF-8");
            xxdz  = new String(xxdz.getBytes("ISO-8859-1"),"UTF-8");
            kfdh  = new String(kfdh.getBytes("ISO-8859-1"),"UTF-8");
            fzr  = new String(fzr.getBytes("ISO-8859-1"),"UTF-8");
            lxrdh  = new String(lxrdh.getBytes("ISO-8859-1"),"UTF-8");
            zdmj  = new String(zdmj.getBytes("ISO-8859-1"),"UTF-8");
            jzmj  = new String(jzmj.getBytes("ISO-8859-1"),"UTF-8");
            ggcsmj  = new String(ggcsmj.getBytes("ISO-8859-1"),"UTF-8");
            lhmj  = new String(lhmj.getBytes("ISO-8859-1"),"UTF-8");
            sjcwmj  = new String(sjcwmj.getBytes("ISO-8859-1"),"UTF-8");
            ckmj  = new String(ckmj.getBytes("ISO-8859-1"),"UTF-8");
            bz  = new String(bz.getBytes("ISO-8859-1"),"UTF-8");

            return gd.getTjxx(xqmc,szdq,xxdz,kfdh,fzr,lxrdh,zdmj,jzmj,ggcsmj,lhmj,sjcwmj,ckmj,cws,bz,newfilename);

        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }


    /**
     * 模态框添加小区信息
     */
//    @RequestMapping(value = "uploadxqbj", method = RequestMethod.POST)
//    @ResponseBody
//    public Object upload(MultipartFile xqbj) {
//        System.out.println(xqbj);
//        return null;
//    }

    /**
     * 模态框修改小区信息
     */
    @RequestMapping(value = "getXgxq", method = RequestMethod.POST)
    @ResponseBody
    public Object getXgxq( MultipartFile tp,String xqmc, String szdq, String xxdz,
                           String kfdh, String fzr, String lxrdh, String zdmj, String jzmj, String ggcsmj,
                           String lhmj, String sjcwmj, String ckmj, Integer cws, String bz,String vid) {
        try {
            xqmc  = new String(xqmc.getBytes("ISO-8859-1"),"UTF-8");
            szdq  = new String(szdq.getBytes("ISO-8859-1"),"UTF-8");
            xxdz  = new String(xxdz.getBytes("ISO-8859-1"),"UTF-8");
            kfdh  = new String(kfdh.getBytes("ISO-8859-1"),"UTF-8");
            fzr  = new String(fzr.getBytes("ISO-8859-1"),"UTF-8");
            lxrdh  = new String(lxrdh.getBytes("ISO-8859-1"),"UTF-8");
            zdmj  = new String(zdmj.getBytes("ISO-8859-1"),"UTF-8");
            jzmj  = new String(jzmj.getBytes("ISO-8859-1"),"UTF-8");
            ggcsmj  = new String(ggcsmj.getBytes("ISO-8859-1"),"UTF-8");
            lhmj  = new String(lhmj.getBytes("ISO-8859-1"),"UTF-8");
            sjcwmj  = new String(sjcwmj.getBytes("ISO-8859-1"),"UTF-8");
            ckmj  = new String(ckmj.getBytes("ISO-8859-1"),"UTF-8");
            bz  = new String(bz.getBytes("ISO-8859-1"),"UTF-8");
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }

        String uploadFileName = tp.getOriginalFilename();
        String[]  os=uploadFileName.split("\\.");
        String newfilename = System.currentTimeMillis()+"."+os[1];
        String url1 = session.getServletContext().getRealPath("/");
        String url2=url1+"\\img\\"+newfilename;
        File newFile1 = new File(url2);


        try {
            tp.transferTo(newFile1);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        return gd.getXgxq(  newfilename, xqmc,  szdq,  xxdz,
                 kfdh,  fzr,  lxrdh,  zdmj,  jzmj,  ggcsmj,
                 lhmj,  sjcwmj,  ckmj,  cws,  bz ,vid);

    }

    //楼宇管理
    /**
     * 加载字段
     *
     * @return
     */
    @RequestMapping(value = "getXszd", method = RequestMethod.GET)
    @ResponseBody
    public Object getXszd() {
        return gd.getXszd();
    }

    /**
     * 点击删除
     */
    @RequestMapping(value = "getDjsc", method = RequestMethod.GET)
    @ResponseBody
    public Object getDjsc(String tid) {
        return gd.getDjsc(tid);
    }


    /**
     * 模态框添加
     */

    @RequestMapping(value = "getLygl", method = RequestMethod.POST)
    @ResponseBody
    public Object getTjxx(Lygl lytj) {
        return gd.getLygl(lytj);
    }
    /**
     * 修改楼宇
     */
    @RequestMapping(value = "getXuiga",method = RequestMethod.POST)
    @ResponseBody
   public Object getXuiga(Lygl lytj){

        return gd.getXuiga(lytj);
    }

//    /**
//     * 修改信息显示字段
//     */
//   @RequestMapping(value = "getXiugai",method = RequestMethod.POST)
//   @ResponseBody
//   public Object getXiugai(){
//       return gd.getXiugai();
//   }

    /**
     * 下拉框获取值
     * @param
     * @return
     */
    @RequestMapping(value = "getxiala",method = RequestMethod.GET)
    @ResponseBody
    public Object getxl(){
        return gd.getall();
    }
    /**
     * 单元
     */
    @RequestMapping(value = "getDanyuan",method = RequestMethod.GET)
    @ResponseBody
    public Object getDanyuan(Dygl dygl){
        return gd.getDanyuan(dygl);
    }
    /**
     * 楼宇查询
     */
    @RequestMapping(value = "getChaxun",method = RequestMethod.GET)
    @ResponseBody
    public Object getChaxun(String inpu){
        return gd.getChaxun(inpu);
    }
    /**
     * 判断是否能删除
     */
    @RequestMapping(value = "getshanchu1",method = RequestMethod.GET)
    @ResponseBody
    public Object getshanchu1(int vid){
        return gd.getshanchu1(vid);
    }
}
